package com.example.demo.controller;

import com.example.demo.common.R;
import com.example.demo.common.RPage;
import com.example.demo.decorator.Authorize;
import com.example.demo.entity.allContents.*;
import com.example.demo.service.AllContentsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/all-contents")
public class AllContentsController {
    @Autowired
    private AllContentsService allContentsService;

    @GetMapping
    @Authorize(
            permission = "main::allContents:selList",
            label = "分页查询内容"
    )
    public R<RPage<AllContents>> selAllContents(@ModelAttribute AllContentsSelList allContentsSelList) {
        return allContentsService.selAllContents(allContentsSelList);
    }

    @GetMapping("/all")
    @Authorize(
            permission = "main::allContents:selAll",
            label = "查询所有内容"
    )
    public R<List<AllContents>> selAllAllContents(@ModelAttribute AllContentsSelAll allContentsSelAll) {
        return allContentsService.selAllAllContents(allContentsSelAll);
    }

    @GetMapping("/ids")
    @Authorize(
            permission = "main::allContents:selOnes",
            label = "查询多个内容（根据id）"
    )
    public R<List<AllContents>> selOnesAllContents(@RequestParam Map<String, String> ids) {
        return allContentsService.selOnesAllContents(ids.values().stream().map(Integer::valueOf).toList().toArray(new Integer[0]));
    }

    @GetMapping("/{id}")
    @Authorize(
            permission = "main::allContents:selOne",
            label = "查询单个内容"
    )
    public R<AllContents> selOneAllContents(@PathVariable Integer id) {
        return allContentsService.selOneAllContents(id);
    }

    @PostMapping
    @Authorize(
            permission = "main::allContents:ins",
            label = "新增内容"
    )
    public R<Boolean> insAllContents(@RequestBody AllContentsInsOne allContentsInsOne) {
        return allContentsService.insAllContents(allContentsInsOne);
    }

    @PostMapping("/s")
    @Authorize(
            permission = "main::allContents:inss",
            label = "批量新增内容"
    )
    public R<Boolean> insAllContentss(@RequestBody AllContentsInsOne[] allContentsInsOnes) {
        return allContentsService.insAllContentss(allContentsInsOnes);
    }

    @PutMapping
    @Authorize(
            permission = "main::allContents:upd",
            label = "修改内容"
    )
    public R<Boolean> updAllContents(@RequestBody AllContentsUpdOne allContentsUpdOne) {
        return allContentsService.updAllContents(allContentsUpdOne);
    }

    @PutMapping("/s")
    @Authorize(
            permission = "main::allContents:upds",
            label = "批量修改内容"
    )
    public R<Boolean> updAllContentss(@RequestBody AllContentsUpdOne[] allContentsUpdOnes) {
        return allContentsService.updAllContentss(allContentsUpdOnes);
    }

    @DeleteMapping
    @Authorize(
            permission = "main::allContents:del",
            label = "删除内容"
    )
    public R<Boolean> delAllContents(@RequestBody Integer[] ids) {
        return allContentsService.delAllContents(ids);
    }
}
